﻿//
// Created by Administrator on 2022/6/12.
//
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <time.h>
//#include <WinSock2.h>
#include "utils.h"
#include "wx/wx.h"

void GetNowTime( char* current ){
    //timespec time;
    //clock_gettime(CLOCK_REALTIME, &time); //获取相对于1970到现在的秒数
    tm nowTime;
    time_t t = time(nullptr);
    //localtime_r(&time.tv_sec, &nowTime);
    localtime_s( &nowTime, &t );
    //char current[1024];
    sprintf(current, "%04d年%02d月%02d日%02d:%02d:%02d", nowTime.tm_year + 1900, nowTime.tm_mon + 1, nowTime.tm_mday,
            nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec);
}

void SetNonBlocking(int sock){
    unsigned long ul=1;
    //SOCKET s=socket(AF_INET,SOCK_STREAM,0);
    int ret = ioctlsocket( sock, FIONBIO,
            (unsigned long *)&ul);//设置成非阻塞模式。
    if( ret==SOCKET_ERROR ){
        perror("fcntl(sock,GETFL)");
        exit(1);
    }
}

void setBlocking( int sock ){
   // int s = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);
}

string ConvertTitle( string key ) {
    string::size_type position = key.find("_");
    while (position != key.npos) {
        key = key.replace(key.find("_"), 1, "-");
        position = key.find("_");
    }
    return key;
}

void GuiCmdParamErrorMsg( const string& key ){
    wxString tmp;
    tmp.sprintf( "%s node not exists.", key );
    wxMessageBox( tmp, _("Error"),
            wxCENTRE | wxOK | wxICON_ERROR );
}

void GuiErrorMsg( const string& msg ){
    wxMessageBox( msg, _("Error"),
                  wxCENTRE | wxOK | wxICON_ERROR );
}

void GuiErrorMsg( const wxString& msg ){
    wxMessageBox( msg, _("Error"),
                  wxCENTRE | wxOK | wxICON_ERROR );
}

